package org.gwu.seuss.persistence;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.gwu.seuss.domain.Shared;

public interface SharedMapper {

	@Select("SELECT * FROM shared")
	public List<Shared> selectAllSharedFiles();
	
	@Select("SELECT * FROM shared WHERE sharedUserId = #{userId}")
	public List<Shared> selectAllSharedByUserId(@Param("userId") int userId);
	
	@Select("SELECT * FROM shared WHERE sharedUserId = #{userId} and fileId = #{fileId}")
	public List<Shared> selectAllSharedByUserIdAndFileId(@Param("userId") int userId, @Param("fileId") int fileId );
	
	@Insert("INSERT INTO shared (sharedUserId,fileId,permissionId) VALUES ( #{sharedUserId}, #{fileId}, #{permissionId} )")
	@Options(useGeneratedKeys=true, keyProperty="sharedId", keyColumn="sharedId")
	public int insertShared(Shared shared);
	
	//@Update("UPDATE shared SET sharedUserId = #{sharedUserId}, fileId = #{fileId}, permissionId = #{permissionId}, deleted = #{deleted} WHERE sharedId = #{sharedId}")
	
	@Update("UPDATE shared SET permissionId = #{permissionId} WHERE sharedId = #{sharedId}")
	public int updatePermissionBySharedId(@Param("permissionId") int permissionId, @Param("sharedId") int sharedId);
	
	@Delete("DELETE FROM shared WHERE sharedId = #{sharedId}")
	public int hardDeleteSharedBySharedId(@Param("sharedId") int sharedId);
	
}
